#!/bin/bash
clear

TEXT='\033[30;107;2m'
INFO='\033[97;44m'
WARNING='\033[97;43m'
ERROR='\033[97;41m'
SUCCESS='\033[97;42m'
GREEN='\033[92m'
YELLOW='\033[93m'
RESET='\033[0m'

if [[ "$EUID" -ne 0 ]]; then
  echo -e "\033[1;31m Anda tiada kebenaran untuk menjalankan skrip ini! \033[0m"; exit 1
fi

function sysinfo {
	# Reading CPU model
	cname=$( awk -F: '/model name/ {name=$2} END {print name}' /proc/cpuinfo | sed 's/^[ \t]*//;s/[ \t]*$//' )

	# Reading amount of CPU cores
	cores=$( awk -F: '/model name/ {core++} END {print core}' /proc/cpuinfo )

	# Reading CPU frequency in MHz
	freq=$( awk -F: ' /cpu MHz/ {freq=$2} END {print freq}' /proc/cpuinfo | sed 's/^[ \t]*//;s/[ \t]*$//' )

	# Reading total memory in MB
	tram=$( free -m | awk 'NR==2 {print $2}' )

	# Reading Swap in MB
	vram=$( free -m | awk 'NR==4 {print $2}' )

	# Reading system uptime
	up=$( uptime | awk '{ $1=$2=$(NF-6)=$(NF-5)=$(NF-4)=$(NF-3)=$(NF-2)=$(NF-1)=$NF=""; print }' | sed 's/^[ \t]*//;s/[ \t]*$//' )

	# Reading operating system and version (simple, didn't filter the strings at the end...)
	opsy=$( cat /etc/issue.net | awk 'NR==1 {print}' ) # Operating System & Version
	arch=$( uname -m ) # Architecture
	lbit=$( getconf LONG_BIT ) # Architecture in Bit
	hn=$( hostname ) # Hostname
	kern=$( uname -r )

	# Output of results
	echo
	echo -e " ========================== "
	echo -e " System Info                "
	echo -e " -------------------------- "
	echo -e " Processor: $cname"
	echo -e " CPU Cores: $cores"
	echo -e " Frequency: $freq MHz"
	echo -e "    Memory: $tram MB"
	echo -e "      Swap: $vram MB"
	echo -e "    Uptime: $up"
	echo -e ""
	echo -e "        OS: $opsy"
	echo -e "      Arch: $arch ($lbit Bit)"
	echo -e "    Kernel: $kern"
	echo -e "  Hostname: $hn"
	echo
}
sysinfo
